import sys
import os

print("=== Python 导入诊断 ===")
print(f"当前工作目录: {os.getcwd()}")
print(f"Python 版本: {sys.version}")
print()

# 添加项目根目录到 Python 路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)
print(f"添加到路径的项目根目录: {project_root}")
print()

print("Python 路径:")
for i, path in enumerate(sys.path):
    print(f"  {i}: {path}")
print()

# 检查 storage 目录是否存在
storage_path = os.path.join(project_root, "storage")
print(f"Storage 目录存在: {os.path.exists(storage_path)}")
if os.path.exists(storage_path):
    print(f"Storage 目录内容: {os.listdir(storage_path)}")
print()

# 检查 __init__.py 文件
init_file = os.path.join(storage_path, "__init__.py")
print(f"__init__.py 文件存在: {os.path.exists(init_file)}")
if os.path.exists(init_file):
    with open(init_file, 'r') as f:
        content = f.read()
        print(f"__init__.py 内容:\n{content}")
print()

# 尝试导入 storage 包
try:
    print("尝试导入 storage 包...")
    import storage
    print("导入 storage 包成功!")
    print(f"Storage 包的内容: {dir(storage)}")
    print()
    
    # 尝试导入特定类
    print("尝试导入 PageManager...")
    from storage import PageManager
    print("导入 PageManager 成功!")
    print(f"PageManager: {PageManager}")
    print()
    
    print("尝试导入 BufferPool...")
    from storage import BufferPool
    print("导入 BufferPool 成功!")
    print(f"BufferPool: {BufferPool}")
    print()
    
    print("尝试导入 FileManager...")
    from storage import FileManager
    print("导入 FileManager 成功!")
    print(f"FileManager: {FileManager}")
    
except ImportError as e:
    print(f"导入失败: {e}")
    import traceback
    traceback.print_exc()
except Exception as e:
    print(f"其他错误: {e}")
    import traceback
    traceback.print_exc()

print("=== 诊断结束 ===")